import table
def generateCodeBlock(path):
    language = input("Enter language:")
    codeName = input("Enter code name:")
    code = []

    while True:
        try:
            code.append(input()+'\n')
        except EOFError:
            break
    with open(path, 'w') as f:
        f.write(table.printBackSlash(1)+"begin{lstlisting}[language = %s,frame=shadowbox,title={%s}]\n" % (language,codeName))
        f.writelines(code)
        f.write(table.printBackSlash(1)+"end{lstlisting}\n")

fileName = 'demo.tex'
path = '/home/xiaochen/tcipa/Project-Report-TR-PPP-Template-1.0/'+fileName

generateCodeBlock(path)